package com.tledu.schedulingInfo.controller;

import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.schedulingInfo.domain.SchedulingInfo;
import com.tledu.schedulingInfo.domain.dto.SchedulingInfoDTO;
import com.tledu.schedulingInfo.service.ISchedulingInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 排班管理Controller
 * 
 * @author ruoyi
 * @date 2024-09-07
 */
@RestController
@RequestMapping("/scheduling/info")
public class SchedulingInfoController extends BaseController
{
    @Autowired
    private ISchedulingInfoService schedulingInfoService;

    /**
     * 查询排班管理列表
     */
    @PreAuthorize("@ss.hasPermi('scheduling:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchedulingInfo schedulingInfo)
    {
        startPage();
        List<SchedulingInfo> list = schedulingInfoService.selectSchedulingInfoList(schedulingInfo);
        return getDataTable(list);
    }

    /**
     * 导出排班管理列表
     */
    @PreAuthorize("@ss.hasPermi('scheduling:info:export')")
    @Log(title = "排班管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchedulingInfo schedulingInfo)
    {
        List<SchedulingInfo> list = schedulingInfoService.selectSchedulingInfoList(schedulingInfo);
        ExcelUtil<SchedulingInfo> util = new ExcelUtil<SchedulingInfo>(SchedulingInfo.class);
        util.exportExcel(response, list, "排班管理数据");
    }

    /**
     * 获取排班管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('scheduling:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(schedulingInfoService.selectSchedulingInfoById(id));
    }

    /**
     * 新增排班管理
     */
    @PreAuthorize("@ss.hasPermi('scheduling:info:add')")
    @Log(title = "排班管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchedulingInfoDTO schedulingInfoDTO)
    {
        return toAjax(schedulingInfoService.insertSchedulingInfo(schedulingInfoDTO));
    }

    /**
     * 修改排班管理
     */
    @PreAuthorize("@ss.hasPermi('scheduling:info:edit')")
    @Log(title = "排班管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchedulingInfoDTO schedulingInfoDTO)
    {
        return toAjax(schedulingInfoService.updateSchedulingInfo(schedulingInfoDTO));
    }

    /**
     * 删除排班管理
     */
    @PreAuthorize("@ss.hasPermi('scheduling:info:remove')")
    @Log(title = "排班管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult removes(@PathVariable Long[] ids)
    {
        return toAjax(schedulingInfoService.deleteSchedulingInfoByIds(ids));
    }

    // @PreAuthorize("@ss.hasPermi('scheduling:info:remove')")
    // @Log(title = "排班管理", businessType = BusinessType.DELETE)
    // @DeleteMapping("/id/{id}")
    // public AjaxResult remove(@PathVariable Long id)
    // {
    //     return toAjax(schedulingInfoService.deleteSchedulingInfoById(id));
    // }
}
